package com.wocao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wocao.entity.SysPost;
import com.wocao.mapper.SysPostMapper;
import com.wocao.service.SysPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 岗位信息表 服务实现类
 * </p>
 *
 * @author Guio
 * @since 2023-11-21
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements SysPostService {

    @Autowired
    private SysPostMapper sysPostMapper;

    @Override
    public IPage<SysPost> getSysPostPage(Long current, Long size, String code, String name, String status) {
        IPage<SysPost> page = sysPostMapper.selectSysPostPage(new Page<SysPost>(current, size), code, name, status);
        return page;
    }

    @Override
    public void addSysPost(SysPost sysPost) throws Exception {
        List<SysPost> postName = sysPostMapper.selectList(new QueryWrapper<SysPost>().eq("post_name", sysPost.getPostName()));
        System.err.println(postName);
        if (!postName.isEmpty()) {
            throw new Exception("岗位名称已存在");
        }
        sysPostMapper.insert(sysPost);
    }

    @Override
    public void deleteIds(List<Long> ids) throws Exception {
        if (ids.isEmpty() || ids.size() == 0) {
            throw new Exception("没有数据");
        }
        sysPostMapper.delete(new QueryWrapper<SysPost>().in("post_id", ids));
    }
}
